# -*- coding:utf-8 -*-
# file: gui.py
# Written by koya
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

import sys

import pygame
from pygame.locals import *

import maths,image,font
import math

# 主菜单类, 主菜单的选项包括 新建游戏, 继续游戏, 设置游戏, 
# 关于游戏, 以及退出功能

class mainmenu_obj ( object ):

    def __init__( self, size, pos ):
        
        
        self.menuitem_texid = [
           0,
           0,
           0,
           0,
           0
           ]
        self.menuitem_texid[0] = image.load_texture( "data//menu//stargatetunnel0.bmp")
        self.menuitem_texid[1] = image.load_texture( "data//menu//stargatetunnel1.bmp")
        self.menuitem_texid[2] = image.load_texture( "data//menu//stargatetunnel2.bmp")
        self.menuitem_texid[3] = image.load_texture( "data//menu//stargatetunnel3.bmp")
        self.menuitem_texid[4] = image.load_texture( "data//menu//stargatetunnel4.bmp")
        
        self.menuitem_count = 0
        for i in self.menuitem_texid:
            self.menuitem_count += 1
           
        self.size = size

        self.alias_angle = int( 360.0 / self.menuitem_count )
        self.radian = self.menuitem_count * 0.3 * self.size
        self.rotate = -90.0

        self.origin_pos_x = pos[0]
        self.origin_pos_y = pos[1]
        self.origin_pos_z = pos[2]
        
        #用于被选中菜单项的旋转
        self.rotate_angle = 0

        #是否开始效果
        self.is_show_effect = False
        self.selected_menuitem_pos = [0.0,0.0,0.0]
        self.other_menuitem_pos_y = 0.0

        self.is_selected = False
        self.selected_menuitem = 'Play'
        
        
    def draw_menu( self ):

        glDisable( GL_DEPTH_TEST )
        glEnable( GL_TEXTURE_2D )
        glEnable( GL_BLEND )
        glBlendFunc( GL_SRC_COLOR, GL_ONE )
        
        glColor4f(1,1,1,1)


        for i in range( 0, self.menuitem_count ):
            
            glPushMatrix()

            glTranslatef( (( self.radian * math.cos( math.radians( self.rotate + self.alias_angle * i ))) + self.origin_pos_x ),\
                         -(( self.radian * math.sin( math.radians( self.rotate+ self.alias_angle * i ))) + self.origin_pos_y ),\
                         self.origin_pos_z )
           
            if self.rotate == ( - 90.0 - self.alias_angle * i ) or self.rotate == ( 270.0 - self.alias_angle * i ):
                  
                  #print i

                  if self.is_show_effect:
                      
                      glTranslatef( self.selected_menuitem_pos[0], \
                                    self.selected_menuitem_pos[1], \
                                    self.selected_menuitem_pos[2] )

                  glRotatef( self.rotate_angle, 1, 1, 1 )
            else:

                if self.is_show_effect:
                    
                    self.other_menuitem_pos_y -= 0.05
                    glTranslatef( 0, self.other_menuitem_pos_y, 0)

            glBindTexture(GL_TEXTURE_2D, self.menuitem_texid[i])
            
            glBegin(GL_QUADS)
            glTexCoord2f( 0.0, 1.0 )
            glVertex3f( -self.size, self.size, 0)
            glTexCoord2f( 0.0, 0.0 )
            glVertex3f( -self.size, -self.size, 0)
            glTexCoord2f( 1.0, 0.0 )
            glVertex3f( self.size, -self.size, 0)
            glTexCoord2f( 1.0, 1.0 )
            glVertex3f( self.size, self.size, 0)
            glEnd()

            glPopMatrix()
            
        self.rotate_angle += 1    

        glDisable( GL_TEXTURE_2D ) 
        glEnable( GL_DEPTH_TEST )
        glDisable( GL_BLEND )
    
    def set_selected_menuitem_pos( self, pos_x, pos_y, pos_z ):
        
        self.selected_menuitem_pos[0] = pos_x
        self.selected_menuitem_pos[1] = pos_y
        self.selected_menuitem_pos[2] = pos_z

    def is_run_effect( self ):
        
        return self.is_show_effect

    def reset( self ):

        self.rotate = -90.0

        self.selected_menuitem_pos[0] = 0.0
        self.selected_menuitem_pos[1] = 0.0
        self.selected_menuitem_pos[2] = 0.0

        self.other_menuitem_pos_y = 0.0

        self.rotate_angle = 0.0

        self.is_selected = False
        self.selected_menuitem = 'Play'


        
    def process_event( self ):
        
        if self.rotate > 360.0:
            self.rotate -= 360.0
        elif self.rotate < -360.0:
            self.rotate += 360.0
                
        # 开始游戏
        if self.rotate == -90.0 or self.rotate == 270.0: 

            self.selected_menuitem = 'Play'
        # 继续游戏
        elif self.rotate == -162.0 or self.rotate == 198.0: 
                    
            self.selected_menuitem = 'Continue'
        # 设置
        elif self.rotate == -234.0 or self.rotate == 126.0: 
                
            self.selected_menuitem = 'Options'
        # 关于
        elif self.rotate == -306.0 or self.rotate == 54.0: 
                    
            self.selected_menuitem = 'About'
        # 退出游戏
        elif self.rotate == -18.0 or self.rotate == 342.0:
                   
            self.selected_menuitem = 'Exit'

        keystate = pygame.key.get_pressed()

        
        events = pygame.event.get()
        for event in events:
            if event.type == QUIT or keystate[K_ESCAPE]:
                 pygame.quit()
                 sys.exit()
            if keystate[K_RIGHT]:
                self.roll_to_left()
                self.rotate_angle = 0
                
            if keystate[K_LEFT]:
                self.roll_to_right() 
                self.rotate_angle = 0
	        
            if keystate[K_RETURN]:

                self.is_show_effect = not self.is_show_effect
                self.other_menuitem_pos_y = 0
 
                self.is_selected = True

      
        
    def get_selected_menuitem ( self ):
        
        return self.is_selected, self.selected_menuitem
            
    def roll_to_left( self ):

        old_rotate = self.rotate
        while True:
            self.rotate -= 1.0
            self.draw_menu()
            pygame.display.flip()
            if self.rotate == ( old_rotate - self.alias_angle ):
                pygame.event.clear()
                break
            
    def roll_to_right( self ):

        old_rotate = self.rotate
        while True:
            self.rotate += 1.0
            self.draw_menu()
            pygame.display.flip()
            if self.rotate == (old_rotate + self.alias_angle):
                pygame.event.clear()
                break

    def render_menu( self ):

        self.process_event()
        self.draw_menu()
          



# 鼠标类, 用于获取鼠标的信息从而来判断是否按钮等被按下

class cursor_obj ( object ):

    def __init__(self):

        self.image = pygame.Surface((1, 1))
        self.rect = self.image.get_rect()

    def update(self):
        self.rect.topleft = pygame.mouse.get_pos()

# 控件的基类, 用于实现有bouding box的效果
# 并且拥有进行绘制的函数接口

class selected_obj ( object ):

    def __init__( self, rect, alias_length, type = 'PyOpenGL'):

        self.rect_rectangle = rect
        self.alias_length = alias_length

        self.is_highlighted = False
        self.cursor = cursor_obj()

        self.type = type

        self.rectangle_image = pygame.Surface( (self.rect_rectangle.width + 2*self.alias_length,self.rect_rectangle.height + 2*self.alias_length) )
        self.rectangle_image.set_colorkey( (0, 0, 0), RLEACCEL )
        self.rectangle_image.convert()
        pygame.draw.rect(self.rectangle_image, (255,255,255), (0,0, self.rect_rectangle.width +\
                       2*self.alias_length,self.rect_rectangle.height + 2*self.alias_length), 1)

    def set_highlight( self, flag ):

        self.is_highlighted = flag

    def update( self ):

        self.cursor.update()
        if self.cursor.rect.colliderect(self.rect_rectangle):
            self.is_highlighted = True
        else:
            self.is_highlighted = False


    def draw( self  ):

        if self.is_highlighted == True:
            self.draw_rectangle()


    def draw_rectangle( self ):
        
        if self.type == 'PyOpenGL':

            glDisable( GL_TEXTURE_2D )
            glColor4f( 1,1,1,1 )
            glBegin( GL_LINE_STRIP )
            glVertex3f( self.rect_rectangle.left - self.alias_length, self.rect_rectangle.top -  self.alias_length, 0)
            glVertex3f( self.rect_rectangle.left -  self.alias_length, self.rect_rectangle.bottom +  self.alias_length, 0)
            glVertex3f( self.rect_rectangle.right + self.alias_length, self.rect_rectangle.bottom +  self.alias_length, 0)
            glVertex3f( self.rect_rectangle.right +  self.alias_length, self.rect_rectangle.top -  self.alias_length, 0)
            glVertex3f( self.rect_rectangle.left -  self.alias_length, self.rect_rectangle.top -  self.alias_length, 0)
            glEnd()
        else:
            #使用pygame,进行绘制 boudingbox
            # 需要得到surface, 可以传入surface对象
              
            screen = pygame.display.get_surface()
            screen.blit( self.rectangle_image, (self.rect_rectangle.left - self.alias_length, self.rect_rectangle.top -  self.alias_length) )

    def draw_texture( self, image, rect ):

        if self.type == 'PyOpenGL':

            glEnable( GL_TEXTURE_2D )
            glBindTexture( GL_TEXTURE_2D, image )
                    
            glBegin(GL_QUADS)

            glTexCoord2f( 0.0, 1.0 )
            glVertex3f( rect.left, rect.top, 0)
            glTexCoord2f( 0.0, 0.0 )
            glVertex3f( rect.left, rect.bottom, 0)
            glTexCoord2f( 1.0, 0.0 )
            glVertex3f( rect.right, rect.bottom, 0)
            glTexCoord2f( 1.0, 1.0 )
            glVertex3f( rect.right, rect.top, 0)
            glEnd()

            glDisable( GL_TEXTURE_2D )
            glBindTexture( GL_TEXTURE_2D, 0)

        else:
            #pygame的绘制函数
            # 需要得到surface, 可以传入surface对象
            screen = pygame.display.get_surface()
            screen.blit( image, rect )

        


class button2_obj( selected_obj ):

    def __init__(self, text, font, command, pos, text_color, size, sound=None, type = 'PyOpenGL'):

        button_color = 'Blue'
        self.font = font
        
        self.text = text
        self.sound = sound
        self.size = size

        self.pos = pos
        self.rect = Rect( self.pos[0], self.pos[1], self.size[0], self.size[1] )
        
        ######################################
        super( button2_obj, self).__init__( self.rect, 5, type )

        #---------------------------------------------
        if self.type == 'PyOpenGL':

            self.text_texid = image.change_font_to_texture( text, True, text_color)
            self.non_selected_image = image.load_texture( 'data/gui/Button Normal.bmp' )            
            self.selected_image = image.load_texture( 'data/gui/Button Highlighted.bmp' )            
            self.pressed_image = image.load_texture( 'data/gui/Button Pressed.bmp' )
            
        else:
            #pygame的调用函数
            self.text_texid = self.font.render( text, 1, text_color )
            self.text_texid = pygame.transform.scale( self.text_texid, self.size )
            self.non_selected_image = image.load_image( 'gui/Button Normal.bmp' )
            self.non_selected_image = pygame.transform.scale( self.non_selected_image, self.size )
            self.selected_image = image.load_image( 'gui/Button Highlighted.bmp' )
            self.selected_image = pygame.transform.scale( self.selected_image, self.size )
            self.pressed_image = image.load_image( 'gui/Button Pressed.bmp' )
            self.pressed_image = pygame.transform.scale( self.pressed_image, self.size )
        
        self.image = self.non_selected_image
        #---------------------------------------------

        self.command = command
        self.text_color = text_color

        self.normpos = self.rect
        self.selectpos = self.rect

        self.is_selected = False
        self.commanding = False


    def draw( self ):

        #--------------------------------------------


        self.draw_texture( self.image, self.rect )
        self.draw_texture( self.text_texid, self.rect )
       
        #--------------------------------------------
        
        super( button2_obj, self).draw()  


        
    def update( self ):

        super( button2_obj, self).update()
 
        mousebutton = pygame.mouse.get_pressed()
        if self.is_highlighted:

            self.image = self.selected_image
            if mousebutton[0]:
                self.image = self.pressed_image
                self.is_selected = True
                self.commanding = False
            else:
                if self.command is not None and self.is_selected  and not self.commanding:
                    self.commanding = True
                    self.command()
                self.is_selected = False
        else:
            self.is_selected = False
            self.commanding = False
            self.rect = self.normpos
            self.image = self.non_selected_image

# 简单的滚动条控件

class slider2_obj( selected_obj ):

    def __init__(self, pos, size, button_size, value, type = 'PyOpenGL'):

        #--------------------------------------------------

        self.pos = pos
        self.size = size
        self.button_size = button_size
        #self.rect = self.image.get_rect(topleft = self.pos)
        self.rect = Rect( self.pos[0], self.pos[1], self.size[0], self.size[1] )
        #self.buttonrect = self.selected_image.get_rect(topleft = (pos[0] + value, pos[1]))
        self.buttonrect = Rect( self.pos[0] + value, self.pos[1], self.button_size[0], self.button_size[1] )
        
        #################################
        super( slider2_obj, self).__init__( self.rect, 5, type )

        #--------------------------------------------------
        if self.type == 'PyOpenGL':

            self.non_selected_image = image.load_texture( 'data/gui/Slider Button Normal.PNG' )
            self.selected_image = image.load_texture( 'data/gui/Slider Button Highlighted.PNG')
            self.slider_image  = image.load_texture( 'data/gui/slider.PNG' )
        else:
            
            self.non_selected_image = image.load_image( 'gui/Slider Button Normal.PNG' )
            self.non_selected_image = pygame.transform.scale( self.non_selected_image, self.button_size )
            self.selected_image = image.load_image( 'gui/Slider Button Highlighted.PNG')
            self.selected_image = pygame.transform.scale( self.selected_image, self.button_size )
            self.slider_image  = image.load_image( 'gui/slider.PNG' )
            self.slider_image = pygame.transform.scale( self.slider_image, self.size )

        

        self.image = self.slider_image
        self.buttonimage = self.non_selected_image

        self.value = value

        self.normpos = self.rect

        self.is_selected = False
        self.commanding = False

    def update( self ):

        super( slider2_obj, self).update()
         #---------------------------------------------------------
        self.value = self.buttonrect.left - self.rect.left
                
        mousebutton = pygame.mouse.get_pressed()

        if self.cursor.rect.colliderect(self.buttonrect):

            self.buttonimage = self.selected_image
            if mousebutton[0]:
                self.is_selected = True
                

        if self.is_highlighted:
            if mousebutton[0]:
                self.is_selected = True

        if not mousebutton[0]:
            self.is_selected = False
            self.buttonimage = self.non_selected_image

        if self.is_selected:
            self.buttonrect.centerx = self.cursor.rect.centerx
            self.is_highlighted = True


        self.buttonrect = self.buttonrect.clamp(self.rect)



    def draw( self ):



        #-------------------------------------------------------


        glDepthMask( GL_FALSE )

        self.draw_texture( self.image, self.rect )
        self.draw_texture( self.buttonimage, self.buttonrect )
        
        super( slider2_obj, self).draw()  



# 滚动条类, 实现了竖向和横向的滚动条, 并且可以采用OpenGL进行绘制, 
# 或者Pygame进行绘制
# 绘制横向或者竖向的滚动条, 是根据初始化时的size参数来设置

class slider3_obj( selected_obj ):

    def __init__(self, pos, size, button_size, value, type = 'PyOpenGL'):

        #--------------------------------------------------

        self.pos = pos
        self.size = size

        if self.size[0] >= self.size[1]:
            self.slider_type = 'Horizontal'
        else:
            self.slider_type = 'Vertical'

        self.button_size = button_size
        #self.rect = self.image.get_rect(topleft = self.pos)
        self.rect = Rect( self.pos[0], self.pos[1], self.size[0], self.size[1] )
        #self.buttonrect = self.selected_image.get_rect(topleft = (pos[0] + value, pos[1]))

        if self.slider_type == 'Horizontal':

            self.buttonrect = Rect( self.pos[0] + value, self.pos[1], self.button_size[0], self.button_size[1] )

        else:
            self.buttonrect = Rect( self.pos[0], self.pos[1]  + self.rect.height - value, self.button_size[0], self.button_size[1] )

        
        #################################
        super( slider3_obj, self).__init__( self.rect, 5, type )

        #--------------------------------------------------
        if self.type == 'PyOpenGL':
            
            if self.slider_type == 'Vertical':
                image1 = image.load_image( 'gui/Slider Button Normal.PNG' )            
                image2 = image.load_image( 'gui/Slider Button Highlighted.PNG')            
                image3  = image.load_image( 'gui/slider.PNG' )

                image1 = pygame.transform.rotate( image1, -90)
                image2 = pygame.transform.rotate( image2, -90 )
                image3 = pygame.transform.rotate( image3, -90)

                self.non_selected_image = image.load_image_to_texture( image1 )
                self.selected_image = image.load_image_to_texture( image2 )
                self.slider_image  = image.load_image_to_texture( image3 )
            else:
                self.non_selected_image = image.load_texture( 'data/gui/Slider Button Normal.PNG' )
                self.selected_image = image.load_texture( 'data/gui/Slider Button Highlighted.PNG')
                self.slider_image  = image.load_texture( 'data/gui/slider.PNG' )

        else:
            

            self.non_selected_image = image.load_image( 'gui/Slider Button Normal.PNG' )            
            self.selected_image = image.load_image( 'gui/Slider Button Highlighted.PNG')            
            self.slider_image  = image.load_image( 'gui/slider.PNG' )
            if self.slider_type == 'Vertical':

                self.non_selected_image = pygame.transform.rotate( self.non_selected_image, -90)
                self.selected_image = pygame.transform.rotate( self.selected_image, -90 )
                self.slider_image = pygame.transform.rotate( self.slider_image, -90)

            self.non_selected_image = pygame.transform.scale( self.non_selected_image, self.button_size )
            self.selected_image = pygame.transform.scale( self.selected_image, self.button_size )
            self.slider_image = pygame.transform.scale( self.slider_image, self.size )        

        self.image = self.slider_image
        self.buttonimage = self.non_selected_image

        self.value = value

        self.normpos = self.rect

        self.is_selected = False
        self.commanding = False

    def update( self ):

        super( slider3_obj, self).update()
         #---------------------------------------------------------
        if self.slider_type == 'Horizontal':
            self.value = int(self.buttonrect.left - self.rect.left)*100/int(self.rect.width - self.buttonrect.width)
        if self.slider_type == 'Vertical':
            self.value = int(self.rect.bottom - self.buttonrect.bottom)*100/int(self.rect.height - self.buttonrect.height)
                
        mousebutton = pygame.mouse.get_pressed()

        if self.cursor.rect.colliderect(self.buttonrect):

            self.buttonimage = self.selected_image
            if mousebutton[0]:

                self.is_selected = True
                

        if self.is_highlighted:
            if mousebutton[0]:
                self.is_selected = True

        if not mousebutton[0]:
            self.is_selected = False
            self.buttonimage = self.non_selected_image

        if self.is_selected:

            if self.slider_type == 'Vertical':
                self.buttonrect.centery = self.cursor.rect.centery
            if self.slider_type == 'Horizontal':
                self.buttonrect.centerx = self.cursor.rect.centerx

            self.is_highlighted = True


        self.buttonrect = self.buttonrect.clamp(self.rect)



    def draw( self ):



        #-------------------------------------------------------


        self.draw_texture( self.image, self.rect )
        self.draw_texture( self.buttonimage, self.buttonrect )
        
        super( slider3_obj, self).draw()  


           

class static_image_obj( selected_obj ):

    def __init__( self, image_name, pos, size, command, type = 'PyOpenGL'):
        
        self.pos = pos
        self.size = size
        self.image_name = image_name
        self.rect = Rect( self.pos[0], self.pos[1], self.size[0], self.size[1] )

        super( static_image_obj, self ).__init__( self.rect, 5, type )

        if self.type == 'PyOpenGL':

            self.image = image.load_texture( self.image_name )
        else:
            self.image = pygame.image.load( self.image_name ).convert()
            self.image.set_colorkey( (0, 0, 0), RLEACCEL )
            self.image = pygame.transform.scale( self.image, self.size )


        self.command = command
        self.selectpos = self.rect

        self.is_selected = False
        self.commanding = False

    def update( self ):

        super( static_image_obj, self).update()

        mousebutton = pygame.mouse.get_pressed()
        if self.is_highlighted:

            if mousebutton[0]:
                self.is_selected = True
                self.commanding = False
            else:
                if self.command is not None and self.is_selected  and not self.commanding:
                    self.commanding = True
                    self.command( self.image_name )
                self.is_selected = False
        else:
            self.is_selected = False
            self.commanding = False

    def draw( self ):
     
        super( static_image_obj, self).draw() 
        self.draw_texture( self.image, self.rect )
         


class checkdot_obj ( selected_obj ):

    def __init__( self, text, font, command, pos, text_color, checkdot_size, font_size,  type = 'PyOpenGL' ):

        self.font = font
        self.text = text
        self.pos = pos
        self.checkdot_size = checkdot_size
        self.font_size = font_size

        max_height = self.checkdot_size[1]
        if checkdot_size[1] < font_size[1]:
            max_height = font_size[1]


        self.checkdot_rect = Rect( self.pos[0], self.pos[1], self.checkdot_size[0], self.checkdot_size[1] )
        self.font_rect = Rect( self.pos[0] + self.checkdot_size[0], self.pos[1], self.font_size[0], self.font_size[1] )

        self.rect = Rect( self.pos[0], self.pos[1], self.checkdot_size[0] + self.font_size[0], max_height )
        super( checkdot_obj, self ).__init__( self.rect, 5, type )

        if self.type == 'PyOpenGL':

            self.non_selected_image = image.load_texture( 'data/gui/SelectDot.png' )
            self.selected_image = image.load_texture( 'data/gui/CheckDot.png' )
            self.text_texid = image.change_font_to_texture( text, True, text_color)

        else:
            self.text_texid = self.font.render( self.text, True, text_color )
            self.text_texid = pygame.transform.scale( self.text_texid, self.font_size )
            self.non_selected_image = pygame.image.load( 'data/gui/SelectDot.png' ).convert()
            self.non_selected_image.set_colorkey( (0, 0, 0), RLEACCEL )
            self.selected_image = pygame.image.load( 'data/gui/CheckDot.png' ).convert()
            self.selected_image.set_colorkey( (0, 0, 0), RLEACCEL )
            self.non_selected_image = pygame.transform.scale( self.non_selected_image, self.checkdot_size )
            self.selected_image = pygame.transform.scale( self.selected_image, self.checkdot_size )
 
        self.image = self.non_selected_image

        self.command = command
        self.is_selected = False
        self.commanding = False


    def update( self ):
                
        super( checkdot_obj, self).update()
 
        mousebutton = pygame.mouse.get_pressed()
        if self.is_highlighted:

            if self.cursor.rect.colliderect(self.checkdot_rect):
                if mousebutton[0]:
                    self.image = self.selected_image
                    self.is_selected = True
                    self.commanding = False
                else:
                    if self.command is not None and self.is_selected  and not self.commanding:
                        self.commanding = True
                        self.command( self.text )
                    self.is_selected = False
        else:
            self.is_selected = False
            self.commanding = False
            self.image = self.non_selected_image

    def set_seleted( self, flag ):
        if flag == True:
            self.image = self.selected_image

    def draw( self ):
        
        #--------------------------------------------


        self.draw_texture( self.image, self.checkdot_rect )
        self.draw_texture( self.text_texid, self.font_rect )
       
        #--------------------------------------------
        
        super( checkdot_obj, self).draw()  


class scrolled_window( selected_obj ):

    def __init__( self, pos, size, background_image_name, type = 'PyOpenGL' ):
        
        self.pos = pos
        self.size = size
        self.background_image_name = background_image_name



        if type == 'PyOpenGL':
            
            self.background_image = image.load_texture( self.background_image_name )
        
        else:
            self.background_image = pygame.image.load( self.background_image_name ).convert()
            self.background_image.set_colorkey( (0, 0, 0), RLEACCEL )
        
        # 窗口是否有滚动条依照窗口初始化大小以及背景图片的大小来定的
        image_wh = pygame.image.load( self.background_image_name )
        self.max_height = image_wh.get_height()
        self.max_width = image_wh.get_width()

        slider_pos_x = 0.0
        slider_pos_y = 0.0

        if self.max_height < self.size[1]:
            
            slider_pos_y = self.max_height
            self.max_height = self.size[1]
        else:
            slider_pos_y = self.size[1]

        if self.max_width < self.size[0]:
            
            slider_pos_x = self.max_width
            self.max_width = self.size[0]
        else:
            slider_pos_x = self.size[0]

        
        self.rect = Rect( self.pos[0], self.pos[1], slider_pos_x, slider_pos_y )
        
        super( scrolled_window, self ).__init__( self.rect, 5, type )

        self.texcrood_x = 0.0
        self.texcrood_y = 0.0
        
        self.slider_x = slider3_obj((self.pos[0], self.pos[1] + slider_pos_y + 10), ( slider_pos_x, 10 ), ( 10, 10 ), 0, self.type )
        self.slider_y = slider3_obj((self.pos[0] + slider_pos_x + 10, self.pos[1]), ( 10, slider_pos_y ), ( 10, 10 ), 0, self.type )
          
        
        self.selected_pos = [0,0]

        self.cur_image = pygame.Surface( (self.size[0], self.size[1] ) )
        self.cur_image.set_colorkey( (0, 0, 0), RLEACCEL )
        self.cur_image.convert()

        self.font = font.load_font( "Hemi Head 426.TTF", 10)

    def update( self ):

        super( scrolled_window, self).update()

        self.slider_x.update()
        self.slider_y.update()

        self.texcrood_x = self.slider_x.value * float(self.max_width) / 100.0
        self.texcrood_y = self.slider_y.value * float(self.max_height) / 100.0

        if self.texcrood_x >= (self.max_width - self.size[0]):
            self.texcrood_x = self.max_width - self.size[0]
        if self.texcrood_y >= (self.max_height - self.size[1]):
            self.texcrood_y = self.max_height - self.size[1]
 
        mousebutton = pygame.mouse.get_pressed()
        if self.is_highlighted:

                if mousebutton[0]:
                    self.is_selected = True
                    
                    self.selected_pos[0] = int(pygame.mouse.get_pos()[0] + self.texcrood_x - self.pos[0])
                    self.selected_pos[1] = int(self.size[1] - pygame.mouse.get_pos()[1] + self.texcrood_y + self.pos[1])

                else:
                    self.is_selected = False
        else:
            self.is_selected = False

    def is_visiable( self, position_x, position_y ):

        if ( position_y - self.texcrood_y ) >= 0 and ( position_y - self.texcrood_y ) <= self.size[1] and \
                ( position_x - self.texcrood_x ) >= 0 and ( position_x - self.texcrood_x ) <= self.size[0]:

            return True, [( position_x - self.texcrood_x + self.pos[0]), ( self.texcrood_y - position_y + self.size[1] + self.pos[1] )]
        
        else:
            return False,[]


    def draw( self ):
        
        #--------------------------------------------


        self.draw_subtexture( self.background_image, self.rect )
        
        self.slider_x.draw()
        self.slider_y.draw()
        #--------------------------------------------
        
        super( scrolled_window, self).draw()  

    def draw_subtexture(self, image, rect ):

        if self.type == 'PyOpenGL':

            if float(self.texcrood_x + self.size[0])/float(self.max_width) >= 1.0:
                self.texcrood_x = self.max_width - self.size[0]
            if float(self.texcrood_y + self.size[1])/float( self.max_height ) >= 1.0:
                self.texcrood_y = self.max_height - self.size[1]

            glEnable( GL_TEXTURE_2D )
            glBindTexture( GL_TEXTURE_2D, image )
                    
            glBegin(GL_QUADS)

            glTexCoord2f( float(self.texcrood_x)/float(self.max_width),\
                        float( self.texcrood_y + self.size[1] )/float( self.max_height ))
            glVertex3f( rect.left, rect.top, 0)
            glTexCoord2f( float(self.texcrood_x)/float(self.max_width),\
                     float( self.texcrood_y )/float( self.max_height ))
            glVertex3f( rect.left, rect.bottom, 0)
            glTexCoord2f( float(self.texcrood_x + self.size[0])/float(self.max_width),\
                        float( self.texcrood_y )/float( self.max_height ))
            glVertex3f( rect.right, rect.bottom, 0)
            glTexCoord2f( float(self.texcrood_x + self.size[0] )/float(self.max_width),\
                        float( self.texcrood_y + self.size[1] )/float( self.max_height ))
            glVertex3f( rect.right, rect.top, 0)
            glEnd()

            glDisable( GL_TEXTURE_2D )
            glBindTexture( GL_TEXTURE_2D, 0)

        else:
            #pygame的绘制函数
            # 需要得到surface, 可以传入surface对象

            #self.cur_image.blit( image, (-self.texcrood_x, - self.max_height + self.texcrood_y + self.size[1]) )
            screen = pygame.display.get_surface()
            #screen.blit( self.cur_image, (self.rect.left, self.rect.top) )
            for i in xrange( 11 ):
                font_image = self.font.render( "%d"%(self.texcrood_y + self.size[1] *  i * 0.1), 1, (255,255,255) )
                screen.blit( font_image, ( self.pos[0] + 2, self.pos[1] + self.size[1] * (1 - i * 0.1)) )

            for i in xrange( 11 ):
                font_image = self.font.render( "%d"%(self.texcrood_x + self.size[0] *  i * 0.1), 1, (255,255,255) )
                screen.blit( font_image, ( self.pos[0] + self.size[0] *  i * 0.1, self.pos[1] - self.alias_length - 10) )


##----------------------------------------------------------------------------------------------------




# 简单的按钮功能

class button_obj( object ):

    def __init__(self, text, font, command, pos, text_color, size, sound=None):

        button_color = 'Blue'
        self.font = font
        self.text_ren = text
        self.text_texid = image.change_font_to_texture( text, True, text_color)
        self.shadow_texid = image.change_font_to_texture(text, True, (0, 0, 0))

        self.sound = sound
        self.size = size

        #---------------------------------------------
        self.non_selected_image = image.load_texture( 'data//gui//Button Normal.bmp' )
        self.selected_image = image.load_texture( 'data//gui//Button Highlighted.bmp' )
        self.pressed_image = image.load_texture( 'data//gui//Button Pressed.bmp' )
        self.image = self.non_selected_image
        #---------------------------------------------

        self.pos = pos
        self.rect = Rect( self.pos[0], self.pos[1], self.size[0], self.size[1] )

        self.cursor = cursor_obj()
        self.command = command

        self.text_color = text_color

        self.normpos = self.rect
        #self.selectpos = self.image.get_rect(topleft = self.pos).move(3, 3)
        self.selectpos = self.rect#.move(3, 3)
        self.text_indent = 0

        self.selected = False
        self.commanding = False
        self.highlighted = False


    def render( self ):

        self.text = self.font.render(str(self.text_ren), 1, self.text_color)
        self.cursor.update()
        mousebutton = pygame.mouse.get_pressed()

        #--------------------------------------------

        glEnable( GL_BLEND )
        glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR)

        glDepthMask( GL_FALSE )

        self.draw_texture( self.image, self.rect )
        self.draw_texture( self.text_texid, self.rect )
        self.draw_texture( self.shadow_texid, self.rect )
        
        glDisable( GL_BLEND )
        glDepthMask( GL_TRUE )
        #--------------------------------------------
          
        
        if self.cursor.rect.colliderect(self.rect):
            self.image = self.selected_image
            self.highlighted = True
            if mousebutton[0]:
                if not self.selected and self.sound is not None:
                    pass
                self.selected = True
                self.image = self.pressed_image
                self.text_indent = 4
                self.commanding = False
            else:
                if self.command is not None and self.selected and not self.commanding:
                    self.commanding = True
                    self.command()

                self.selected = False         
                
                self.text_indent = 0
        else:
            self.highlighted = False
            self.commanding = False
            self.text_indent = 0
            self.selected = False
            self.rect = self.normpos
            self.image = self.non_selected_image


    def draw_texture( self, texid, rect ):
        
        glColor4f(1,1,1,1)
        glEnable( GL_TEXTURE_2D )
        glBindTexture( GL_TEXTURE_2D, texid )
            
        glBegin(GL_QUADS)

        glTexCoord2f( 0.0, 1.0 )
        glVertex3f( rect.left, rect.top, 0)
        glTexCoord2f( 0.0, 0.0 )
        glVertex3f( rect.left, rect.bottom, 0)
        glTexCoord2f( 1.0, 0.0 )
        glVertex3f( rect.right, rect.bottom, 0)
        glTexCoord2f( 1.0, 1.0 )
        glVertex3f( rect.right, rect.top, 0)
        glEnd()

        glDisable( GL_TEXTURE_2D )


# 简单的滚动条控件

class slider_obj( object ):

    def __init__(self, pos, size, button_size, value):

        #--------------------------------------------------
        self.non_selected_image = image.load_texture( 'data/gui/Slider Button Normal.PNG')

        self.selected_image = image.load_texture( 'data/gui/Slider Button Highlighted.PNG')
        
        self.slider_image = image.load_texture( 'data/gui/slider.PNG')
        
        self.image = self.slider_image
        self.buttonimage = self.non_selected_image

        #--------------------------------------------------

        self.pos = pos
        self.size = size
        self.button_size = button_size
        #self.rect = self.image.get_rect(topleft = self.pos)
        self.rect = Rect( self.pos[0], self.pos[1], self.size[0], self.size[1] )
        #self.buttonrect = self.selected_image.get_rect(topleft = (pos[0] + value, pos[1]))
        self.buttonrect = Rect( self.pos[0] + value, self.pos[1], self.button_size[0], self.button_size[1] )

        self.cursor = cursor_obj()
        self.value = value

        self.normpos = self.rect

        self.selected = False
        self.commanding = False


    def draw_texture( self, texid, rect ):
        
        glColor4f( 1,1,1,1)
        glEnable( GL_TEXTURE_2D )
        glBindTexture( GL_TEXTURE_2D, texid )
            
        glBegin(GL_QUADS)

        glTexCoord2f( 0.0, 1.0 )
        glVertex3f( rect.left, rect.top, 0)
        glTexCoord2f( 0.0, 0.0 )
        glVertex3f( rect.left, rect.bottom, 0)
        glTexCoord2f( 1.0, 0.0 )
        glVertex3f( rect.right, rect.bottom, 0)
        glTexCoord2f( 1.0, 1.0 )
        glVertex3f( rect.right, rect.top, 0)
        glEnd()

        glDisable( GL_TEXTURE_2D )

    def render( self ):

        self.value = self.buttonrect.left - self.rect.left
                

        self.cursor.update()
        mousebutton = pygame.mouse.get_pressed()

        #-------------------------------------------------------

        #screen.blit(self.image, self.rect)
        #screen.blit(self.buttonimage, self.buttonrect)
        glEnable( GL_BLEND )
        glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR)

        glDepthMask( GL_FALSE )

        self.draw_texture( self.image, self.rect )
        self.draw_texture( self.buttonimage, self.buttonrect )

        glDisable( GL_BLEND )
        glDepthMask( GL_TRUE )
        #---------------------------------------------------------

        if self.cursor.rect.colliderect(self.buttonrect):

            self.buttonimage = self.selected_image
            if mousebutton[0]:
                self.selected = True

        if self.cursor.rect.colliderect(self.rect):
            if mousebutton[0]:
                self.selected = True

        if not mousebutton[0]:
            self.selected = False
            self.buttonimage = self.non_selected_image

        if self.selected:
            self.buttonrect.centerx = self.cursor.rect.centerx


        self.buttonrect = self.buttonrect.clamp(self.rect)



# 游戏主菜单里面的设置菜单,用于设置游戏的基本信息
# 包括声音,音乐,以及按键
# OptionsMenu 在完成设置之后需要传递 
# self.sound_volume
# self.music_volume
# self.player1_keyboard
# self.player2_keyboard
# 给游戏主程序

class options_menu_obj( object ):

    def __init__( self, font ):

        
        # 声音以及音乐的音量大小
        self.sound_volume = 0.5
        self.music_volume = 0.5

        pygame.mouse.set_visible(1)

        self.is_render_sound_slider = False
        self.is_render_music_slider = False
        self.is_set_keyboard = False

        self.is_render_player1_keyboard = False
        self.is_render_player2_keyboard = False

        self.buttons = []

        self.buttons.append(button_obj('Sound...', font, self.set_sound_volume, (50, 50), (255, 255, 255), (100, 20)))
        self.buttons.append(button_obj('Music...', font, self.set_music_volume, (50, 90), (255, 255, 255), (100, 20)))
        self.buttons.append(button_obj('KeyBoard', font, self.set_keyboard, (50, 130), (255, 255, 255), (100, 20)))

        self.sound_slider = slider_obj((200, 50), ( 100, 15 ), ( 15, 16 ), self.sound_volume * 100 )
        self.music_slider = slider_obj((200, 90), ( 100, 15 ), ( 15, 16 ), self.music_volume * 100 )

       
        # 玩家键位设置按钮
        self.player1_button = button_obj( 'Player1', font, self.show_or_hide_player1_keyboard, (200, 130), (255, 255, 255), (80, 20))
        self.player2_button = button_obj( 'Player2', font, self.show_or_hide_player2_keyboard, (300, 130), (255, 255, 255), (80, 20))


        self.player1_keyboard = {'Up' : K_w, 'Down' : K_s, 'Left' : K_a, 'Right' : K_d, 'Shoot' : K_LCTRL,\
                    'Bomb' : K_LSHIFT }
        self.player2_keyboard = {'Up' : K_UP, 'Down' : K_DOWN, 'Left' : K_LEFT, 'Right' : K_RIGHT, 'Shoot' : K_RCTRL,\
                    'Bomb' : K_RSHIFT }

        self.key_up_texid = image.change_font_to_texture( 'Move Up ', True, (255,255,255))
        self.key_down_texid = image.change_font_to_texture( 'Move Down ', True, (255,255,255))
        self.key_left_texid = image.change_font_to_texture( 'Move Left ', True, (255,255,255))
        self.key_right_texid = image.change_font_to_texture( 'Move Right ', True, (255,255,255))
        self.key_shoot_texid = image.change_font_to_texture( 'Shoot ', True, (255,255,255))
        self.key_bomb_texid = image.change_font_to_texture( 'Bomb ', True, (255,255,255))



        # 用于更改玩家1,以及玩家2的按键
        self.player1_keybuttons = []
        self.player2_keybuttons = []
        
        self.player1_keybuttons.append(button_obj( 'w', font, self.input_new_key, (150, 200), (255, 255, 255), (80, 20)))     
        self.player1_keybuttons.append(button_obj( 's', font, self.input_new_key, (150, 230), (255, 255, 255), (80, 20)))
        self.player1_keybuttons.append(button_obj( 'a', font, self.input_new_key, (150, 260), (255, 255, 255), (80, 20)))
        self.player1_keybuttons.append(button_obj( 'd', font, self.input_new_key, (150, 290), (255, 255, 255), (80, 20)))
        self.player1_keybuttons.append(button_obj( 'LCTRL', font, self.input_new_key, (150, 320), (255, 255, 255), (80, 20)))
        self.player1_keybuttons.append(button_obj( 'LSHIFT', font, self.input_new_key, (150, 350), (255, 255, 255), (80, 20)))
        
        self.player2_keybuttons.append(button_obj( 'Up', font, self.input_new_key, (400, 200), (255, 255, 255), (80, 20)))     
        self.player2_keybuttons.append(button_obj( 'Down', font, self.input_new_key, (400, 230), (255, 255, 255), (80, 20)))
        self.player2_keybuttons.append(button_obj( 'Left', font, self.input_new_key, (400, 260), (255, 255, 255), (80, 20)))
        self.player2_keybuttons.append(button_obj( 'Right', font, self.input_new_key, (400, 290), (255, 255, 255), (80, 20)))
        self.player2_keybuttons.append(button_obj( 'RCTRL', font, self.input_new_key, (400, 320), (255, 255, 255), (80, 20)))
        self.player2_keybuttons.append(button_obj( 'RSHIFT', font, self.input_new_key, (400, 350), (255, 255, 255), (80, 20)))
        
        #禁止的键位设置
        self.forbid_key = [K_NUMLOCK, K_CAPSLOCK, K_SCROLLOCK, K_ESCAPE]

    def render( self ):


        self.sound_volume = float(self.sound_slider.value/100.0)
        self.music_volume = float(self.music_slider.value/100.0)
        

        for button in self.buttons:
            button.render()

        if self.is_render_sound_slider:
            self.sound_slider.render()

        if self.is_render_music_slider:
            self.music_slider.render()

        if self.is_set_keyboard:

            self.player1_button.render()
            self.player2_button.render()
            self.to_set_keyboard()

        pygame.display.flip()
        
    def draw_texture( self, texid, rect ):

        glColor4f(1,1,1,1)

        glEnable( GL_TEXTURE_2D )
        glBindTexture( GL_TEXTURE_2D, texid )
            
        glBegin(GL_QUADS)

        glTexCoord2f( 0.0, 1.0 )
        glVertex3f( rect.left, rect.top, 0)
        glTexCoord2f( 0.0, 0.0 )
        glVertex3f( rect.left, rect.bottom, 0)
        glTexCoord2f( 1.0, 0.0 )
        glVertex3f( rect.right, rect.bottom, 0)
        glTexCoord2f( 1.0, 1.0 )
        glVertex3f( rect.right, rect.top, 0)
        glEnd()

        glDisable( GL_TEXTURE_2D )

    def set_sound_volume( self ):
       
        self.is_render_sound_slider = not self.is_render_sound_slider

    def set_music_volume( self ):
        
        self.is_render_music_slider = not self.is_render_music_slider
    
    def show_or_hide_player1_keyboard( self ):

        self.is_render_player1_keyboard = not self.is_render_player1_keyboard

    def show_or_hide_player2_keyboard( self ):

        self.is_render_player2_keyboard = not self.is_render_player2_keyboard

    def set_keyboard( self ):

        self.is_set_keyboard = not self.is_set_keyboard

    def to_set_keyboard( self ):

        if self.is_render_player1_keyboard:
            self.draw_texture( self.key_up_texid, Rect(50, 200, 80, 20) )
            self.draw_texture( self.key_down_texid, Rect(50, 230, 80, 20) )
            self.draw_texture( self.key_left_texid, Rect(50, 260, 80, 20) )
            self.draw_texture( self.key_right_texid, Rect(50, 290, 80, 20) )
            self.draw_texture( self.key_shoot_texid, Rect(50, 320, 80, 20) )
            self.draw_texture( self.key_bomb_texid, Rect(50, 350, 80, 20) )

            for key in self.player1_keybuttons:
                key.render()

        if self.is_render_player2_keyboard:

            self.draw_texture( self.key_up_texid, Rect(300, 200, 80, 20) )
            self.draw_texture( self.key_down_texid, Rect(300, 230, 80, 20) )
            self.draw_texture( self.key_left_texid, Rect(300, 260, 80, 20) )
            self.draw_texture( self.key_right_texid, Rect(300, 290, 80, 20) )
            self.draw_texture( self.key_shoot_texid, Rect(300, 320, 80, 20) )
            self.draw_texture( self.key_bomb_texid, Rect(300, 350, 80, 20) )

            for key in self.player2_keybuttons:
                key.render()

    def set_w_key( self ):

        #keystates = pygame.key.get_pressed()
        
        #index = 0
        #for key in keystate:
        #    if key:
        #        if not find_in_list( index, forbid_key ):
        #            self.player1_keyboard['Up'] = index
        #    index += 1
        pass

    def input_new_key( self ):


        keystates = pygame.key.get_pressed()
        for event in pygame.event.get():
            for key in keystates:
                if key is True:
                    print key
        pass


# 游戏里面的玩家界面, 包括Hp,Exp,Score等
class user_gui:

    def __init__( self, player_mode, max_hp, max_exp, max_mp, screen_width = 512, screen_height = 640):
        
        #player 1 or 2
        #player_mode = 'Player1' or player_mode = 'Player2'
        self.player_mode = player_mode

        self.hp_bar = image.load_image( 'Hp.PNG', 'data//gui//')
        self.exp_bar = image.load_image( 'Exp.png', 'data//gui//')
        self.mp_bar = image.load_image( 'Shield.png', 'data//gui//')
        self.mp_bar = pygame.transform.scale( self.mp_bar, ( self.mp_bar.get_width() * 0.5, self.mp_bar.get_height() * 0.5))
        self.mp_image = image.load_image(  'mp.png', 'data//gui//')
        
        self._hp_bar = self.hp_bar
        self._exp_bar = self.exp_bar
        self._mp_bar = self.mp_bar

        self.border_bar = image.load_image( 'Metal Bar.png', 'data//gui//')

        self.max_hp = max_hp
        self.max_exp = max_exp
        self.cur_hp = self.max_hp
        self.cur_exp = self.max_exp
        
        #---------------
        self.max_mp = max_mp
        self.cur_mp = 0
        self.mp_num = 0
        #----------------
        self.score = 0
        self.cur_level = "[?]"

        self.bomb_num = 0
        self.lives = 0

        self.screen_width = screen_width
        self.screen_height = screen_height

        self.font = font.load_font( "Hemi Head 426.TTF", 15)

    def set_player_info( self, player_hp, player_max_hp, player_exp, player_max_exp,\
               player_mp, player_max_mp, player_mp_num, player_score, player_lives = 0, player_bomb_num = 0 ):

        self.cur_hp = player_hp
        self.cur_exp = player_exp

        self.max_hp = player_max_hp
        self.max_exp = player_max_exp

        #--------------------------
        self.cur_mp = player_mp
        self.max_mp = player_max_mp
        self.mp_num = player_mp_num

        self.score = player_score

        self.lives = player_lives
        self.bomb_num = player_bomb_num

    def set_cur_level( self, cur_level ):

        self.cur_level = cur_level


    def update( self ):

       
        hp_scale = float(self.cur_hp) / float(self.max_hp) * self._hp_bar.get_width()
        exp_scale = float(self.cur_exp) / float(self.max_exp) * self._exp_bar.get_width()

        #---------------------------
        mp_scale = float(self.cur_mp) / float(self.max_mp) * self._mp_bar.get_width()
        self.mp_bar = pygame.transform.scale( self._mp_bar, ( mp_scale, self._mp_bar.get_height()))
        
        self.hp_bar = pygame.transform.scale( self._hp_bar, ( hp_scale, self._hp_bar.get_height()))
        self.exp_bar = pygame.transform.scale( self._exp_bar,( exp_scale, self._exp_bar.get_height()))

    def render( self, screen ):

        font_image = self.font.render( "Stage: %s" %self.cur_level, 1, (255,255,255) )
        screen.blit( font_image, (200,600) )
        
        if self.player_mode == 'Player1':

            #player 1
            font_image = self.font.render( "Hp  ", 1, (255,255,255) )
            screen.blit( font_image, (2,5) )

            screen.blit( self.hp_bar, (40,12) )
            screen.blit( self.border_bar, ( 37, 9 ) )
           
            str = "%s"%self.cur_hp + "/" + "%s"%self.max_hp
            font_image = self.font.render( "%s" %str, 1, (255,255,255) )
            screen.blit( font_image, (50 + self._hp_bar.get_width(),9) )


            font_image = self.font.render( "Exp ", 1, (255,255,255) )
            screen.blit( font_image, (2,20) )

            screen.blit( self.exp_bar, ( 40, 27) )
            screen.blit( self.border_bar, ( 37, 24 ) )

            str = "%s"%self.cur_exp + "/" + "%s"%self.max_exp
            font_image = self.font.render( "%s" %str, 1, (255,255,255) )
            screen.blit( font_image, (50 + self._exp_bar.get_width(),24) )

            #-----------------------------------
            font_image = self.font.render( "Mp ", 1, (255,255,255) )
            screen.blit( font_image, (2,35) )

            screen.blit( self.mp_bar, ( 40, 40) )
            screen.blit( self.border_bar, ( 37, 39 ) )

            str = "%s"%self.cur_mp + "/" + "%s"%self.max_mp
            font_image = self.font.render( "%s" %str, 1, (255,255,255) )
            screen.blit( font_image, (50 + self._mp_bar.get_width(),39) )

            font_image = self.font.render( "Magic Attack: ", 1, (255,255,255) )
            screen.blit( font_image, (2,55) )
            
            for i in xrange( int(self.mp_num) ):
                screen.blit( self.mp_image, (100 + 28 * i,53) )


            #------------------------------------------


            font_image = self.font.render( "Player1 Score:  %d" %self.score, 1, (255,255,255) )
            screen.blit( font_image, (2,600) )

            font_image = self.font.render( "Life:  %d" %self.lives, 1, (255,255,255) )
            screen.blit( font_image, (2,615) )
            font_image = self.font.render( "Bomb:  %d" %self.bomb_num, 1, (255,255,255) )
            screen.blit( font_image, (100,615) )

        if self.player_mode == 'Player2':

            #player 2
            font_image = self.font.render( "Hp  ", 1, (255,255,255) )
            screen.blit( font_image, (272,5) )

            screen.blit( self.hp_bar, (310,12) )
            screen.blit( self.border_bar, ( 307, 9 ) )

            str = "%s"%self.cur_hp + "/" + "%s"%self.max_hp
            font_image = self.font.render( "%s" %str, 1, (255,255,255) )
            screen.blit( font_image, (320 + self._hp_bar.get_width(),9) )

            font_image = self.font.render( "Exp ", 1, (255,255,255) )
            screen.blit( font_image, (272,20) )

            screen.blit( self.exp_bar, ( 310, 27) )
            screen.blit( self.border_bar, ( 307, 24 ) )

            str = "%s"%self.cur_exp + "/" + "%s"%self.max_exp
            font_image = self.font.render( "%s" %str, 1, (255,255,255) )
            screen.blit( font_image, (320 + self._exp_bar.get_width(),24) )

            #-----------------------------------
            font_image = self.font.render( "Mp ", 1, (255,255,255) )
            screen.blit( font_image, (272,35) )

            screen.blit( self.mp_bar, ( 310, 40) )
            screen.blit( self.border_bar, ( 307, 39 ) )

            str = "%s"%self.cur_mp + "/" + "%s"%self.max_mp
            font_image = self.font.render( "%s" %str, 1, (255,255,255) )
            screen.blit( font_image, (320 + self._mp_bar.get_width(),39) )

            font_image = self.font.render( "Magic Attack: ", 1, (255,255,255) )
            screen.blit( font_image, (272,55) )
            
            
            for i in xrange( int(self.mp_num) ):
                screen.blit( self.mp_image, (372 + 28 * i,53) )
            #---------------------------------------------


            font_image = self.font.render( "Player2 Score:  %d" %self.score, 1, (255,255,255) )
            screen.blit( font_image, (300,600) )

            font_image = self.font.render( "Life:  %d" %self.lives, 1, (255,255,255) )
            screen.blit( font_image, (300,615) )
            font_image = self.font.render( "Bomb:  %d" %self.bomb_num, 1, (255,255,255) )
            screen.blit( font_image, (400,615) )



   



